/*
 * =====================================================================================
 * Copyright (C) 2023 Ingenic Semiconductor Co.,Ltd
 * All Rights Reserved
 *
 * Filename     : pdma.h
 * Author       : Keven <keven.ywhan@ingenic.com>
 * Created      : 2024/06/25 10:44
 * Description  :
 *
 * =====================================================================================
 */

#ifndef __PDMA_H__
#define __PDMA_H__

enum {
	DMA_RQ_MEM = 0x8,
	DMA_RQ_I2C0_TX = 0x24,
	DMA_RQ_I2C0_RX = 0x25,
	DMA_RQ_I2C1_TX = 0x26,
	DMA_RQ_I2C1_RX = 0x27,
	DMA_RQ_I2C2_TX = 0x28,
	DMA_RQ_I2C2_RX = 0x29,
	DMA_RQ_I2C3_TX = 0x2a,
	DMA_RQ_I2C3_RX = 0x2b,
};

typedef enum {
	DMA_PORT_32BIT = 0,
	DMA_PORT_8BIT = 1,
	DMA_PORT_16BIT = 2,
} DMA_PortWidth;

typedef enum {
	BYTE1 = 1,      /* : 8-bit */
	BYTE2 = 2,      /* : 16-bit */
	BYTE4 = 0,      /* : 32-bit */
	BYTE16 = 3,     /* : 16-byte */
	BYTE32 = 4,     /* : 32-byte */
	BYTE64 = 5,     /* : 64-byte */
	BYTE128 = 6,    /* : 128-byte */
	AUTONOMY = 7,   /* : autonomy */
	EXTR_DECIDE = 8 /* : extr-decide */
} DMA_TransferDataUnit;

struct dma_channel_cfg {
	uint32_t src_addr;
	uint32_t dst_addr;
	uint32_t tran_data_uint;
	uint32_t tran_data_count;
	uint8_t dma_requset_type;
	uint8_t src_addr_inc_en;
	uint8_t dst_addr_inc_en;
	uint8_t src_port_width;
	uint8_t dst_port_width;

	void (*callback)(void *cb_data);
	void *cb_data;

};

int32_t dma_init();
int32_t dma_request_channel();
int32_t dma_relese_channel(uint32_t chn);
int32_t dma_config_channel(uint32_t chn, struct dma_channel_cfg *config);
int32_t dma_start_channel(uint32_t chn);

#endif /* __PDMA_H__ */

